# 首页的路由相关
from flask import Blueprint,jsonify,request
from flask import current_app,render_template
from job.models import Job
from job import db
from sqlalchemy import  *
import sqlalchemy.sql.expression as expr
from sqlalchemy.engine.result import ResultProxy,RowProxy

main = Blueprint("main",__name__)

@main.route("/")
def index():
    return render_template("main.html")

@main.route("/login",methods=['POST'])
def login():
    user = request.form['user']
    password=request.form['password']
    status=0
    if(user=="job" and password =="hello"):
        status=1
    return jsonify({
        "status":status
    })


@main.route("/mytest")
def mytest():

    return render_template("mytest.html")

@main.route("/test")
def test():
    pass
    f = db
    result = db.session.execute("select edu,count(1) from job  group by edu").fetchall()
    res = [ row.values() for row in result]
    return jsonify(res)
    


#省份api测试
@main.route("/provinces")
def provinces():
    
    result =  Job.query.with_entities(Job.province,func.count().label("c")).group_by(Job.province).order_by("c")
    result = result.all()
    provinces=[]
    counts = []
    for item in result:
        # print(item)
        provinces.append(item[0])
        counts.append(item[1])
    return jsonify({
        'provinces':provinces,
        'counts':counts
    })

